public class 仅仅反转字母方法一 {
    //https://leetcode.cn/problems/reverse-only-letters/description/
    //双指针 + 字符串
    public String reverseOnlyLetters(String ss) {
        //转换成字符数组, 交换一下位置比较方便
        char[] s = ss.toCharArray();
        int left = 0;
        int right = s.length - 1;
        //双指针两边判断
        while(left < right){
            //判断左边是不是字母
            char ch = s[left];
            if(!((ch <= 'z' && ch >= 'a') || (ch <= 'Z' && ch >= 'A'))){
                left++;
                continue;
            }
            //判断右边是不是字母
            char ch1 = s[right];
            if(!((ch1 <= 'z' && ch1 >= 'a') || (ch1 <= 'Z' && ch1 >= 'A'))){
                right--;
                continue;
            }
            //都是字母就交换
            swap(s,left++,right--);
        }
        //返回一下最终的字符数组, 转成字符串
        return new String(s);
    }
    public void swap(char[] s,int a,int b){
        char tmp = s[a];
        s[a] = s[b];
        s[b] = tmp;
    }
}
